package com.hutu.core.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.hutu.util.JWTUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.Date;

@Component
public class MpMetaObjectHandler implements MetaObjectHandler {

    /**
     * 插入时的填充策略
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", new Timestamp(new Date().getTime()), metaObject);
        this.setFieldValByName("deleteFlag", 0, metaObject);
        this.setFieldValByName("createUser", JWTUtil.currentUser.get().getId(), metaObject);
        this.setFieldValByName("createUserName", JWTUtil.currentUser.get().getName(), metaObject);

    }

    /**
     * 更新时的填充策略
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Timestamp(new Date().getTime()), metaObject);
    }


}
